Implement -l/--list for `cargo package`
authorAlex Crichton <alex@alexcrichton.com>
Thu, 13 Nov 2014 06:28:30 +0000 (22:28 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 14 Nov 2014 01:29:35 +0000 (17:29 -0800)
This provides a method of listing the files that will be in a package without
actually creating one.

Closes #855

src/bin/package.rs
src/cargo/ops/cargo_package.rs
src/cargo/ops/registry.rs
tests/test_cargo_package.rs

index 108d6b4500f2bbb0aee10037975dd28914d5be60..ed981e742ff16d74ae5466f46985ada609e0d9f0 100644 (file)
@@ -8,6 +8,7 @@ struct Options {
     flag_verbose: bool,
     flag_manifest_path: Option<String>,
     flag_no_verify: bool,
+    flag_list: bool,
 }
 
 pub const USAGE: &'static str = "
@@ -18,8 +19,9 @@ Usage:
 
 Options:
     -h, --help              Print this message
-    --manifest-path PATH    Path to the manifest to compile
+    -l, --list              Print files included in a package without making one
     --no-verify             Don't verify the contents by building them
+    --manifest-path PATH    Path to the manifest to compile
     -v, --verbose           Use verbose output
 
 ";
@@ -27,7 +29,9 @@ Options:
 pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
     shell.set_verbose(options.flag_verbose);
     let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
-    ops::package(&root, shell, !options.flag_no_verify).map(|_| None).map_err(|err| {
+    ops::package(&root, shell,
+                 !options.flag_no_verify,
+                 options.flag_list).map(|_| None).map_err(|err| {
         CliError::from_boxed(err, 101)
     })
 }
index 807e0166bd810d7fb41da3424b9a55900131c022..9330bad4f836f5fe6723c040b4d45b726573eb0e 100644 (file)
@@ -25,15 +25,28 @@ impl Drop for Bomb {
 
 pub fn package(manifest_path: &Path,
                shell: &mut MultiShell,
-               verify: bool) -> CargoResult<Path> {
+               verify: bool,
+               list: bool) -> CargoResult<Option<Path>> {
     let mut src = try!(PathSource::for_path(&manifest_path.dir_path()));
     try!(src.update());
     let pkg = try!(src.get_root_package());
 
+    if list {
+        let root = pkg.get_manifest_path().dir_path();
+        let mut list: Vec<_> = try!(src.list_files(&pkg)).iter().map(|file| {
+            file.path_relative_from(&root).unwrap()
+        }).collect();
+        list.sort();
+        for file in list.iter() {
+            println!("{}", file.display());
+        }
+        return Ok(None)
+    }
+
     let filename = format!("package/{}-{}.crate", pkg.get_name(),
                            pkg.get_version());
     let dst = pkg.get_absolute_target_dir().join(filename);
-    if dst.exists() { return Ok(dst) }
+    if dst.exists() { return Ok(Some(dst)) }
 
     let mut bomb = Bomb { path: Some(dst.clone()) };
 
@@ -46,7 +59,7 @@ pub fn package(manifest_path: &Path,
             human("failed to verify package tarball")
         }))
     }
-    Ok(bomb.path.take().unwrap())
+    Ok(Some(bomb.path.take().unwrap()))
 }
 
 fn tar(pkg: &Package, src: &PathSource, shell: &mut MultiShell,
index f5e9944578c765da753aa75c5b9ae29dba7e1369..723c7f1f51e0301ba217948e1585a56b1a56bcd2 100644 (file)
@@ -33,7 +33,7 @@ pub fn publish(manifest_path: &Path,
     try!(verify_dependencies(&pkg, &reg_id));
 
     // Prepare a tarball
-    let tarball = try!(ops::package(manifest_path, shell, verify));
+    let tarball = try!(ops::package(manifest_path, shell, verify, false)).unwrap();
 
     // Upload said tarball to the specified destination
     try!(shell.status("Uploading", pkg.get_package_id().to_string()));
index d1a9da43df5d645f274b7135fe8471ce7157a66e..c4a07ba27af5dcccc6137ca5912a2f0bfd48a424 100644 (file)
@@ -35,6 +35,11 @@ test!(simple {
         compiling = COMPILING,
         dir = p.url()).as_slice()));
     assert_that(&p.root().join("target/package/foo-0.0.1.crate"), existing_file());
+    assert_that(p.process(cargo_dir().join("cargo")).arg("package").arg("-l"),
+                execs().with_status(0).with_stdout("\
+Cargo.toml
+src[..]main.rs
+"));
     assert_that(p.process(cargo_dir().join("cargo")).arg("package"),
                 execs().with_status(0).with_stdout(""));